import { Application } from 'egg';
import {
  indexRule,
  createRule,
  updateRule,
  destroyRule,
 } from '../validate/shop/qr';

/**
 * 二维码管理
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const {  jwt } = app;

  return {
    'merchant.qr.list': {
      method: 'GET',
      path: '/api/merchant/qr',
      options: {
        tags: ['merchant/list'],
        description: '二维码列表',
        handler: app.controller.shop.qr.list,
        middlewares: [jwt, auth('merchant.qr.list')],
        validate: indexRule,
      },
    },
    'merchant.qr.create': {
      method: 'POST',
      path: '/api/merchant/qr',
      options: {
        tags: ['merchant/create'],
        description: '创建二维码',
        handler: app.controller.shop.qr.create,
        middlewares: [jwt, auth('merchant.qr.create')],
        validate: createRule,
      },
    },
    'merchant.qr.update': {
      method: 'PUT',
      path: '/api/merchant/qr/:id',
      options: {
        tags: ['merchant/update'],
        description: '更新二维码',
        handler: app.controller.shop.qr.update,
        middlewares: [jwt, auth('merchant.qr.update')],
        validate: updateRule,
      },
    },
    'merchant.qr.destroy': {
      method: 'DELETE',
      path: '/api/merchant/qr/:id',
      options: {
        tags: ['merchant/delete'],
        description: '删除二维码',
        handler: app.controller.shop.qr.destroy,
        middlewares: [jwt, auth('merchant.qr.destroy')],
        validate: destroyRule,
      },
    },
  };
};
